#include <iostream>
#include <vector>

using std::cout;
using std::endl;
using std::vector;

void test()
{
    vector<int> number = {1, 3, 4, 4, 4, 5, 4, 4, 7};
    for(auto it = number.begin(); it != number.end(); ++it)
    {
        cout << *it << "   ";
    }

    cout << endl << "执行删除操作" << endl;
    for(auto it = number.begin(); it != number.end(); ++it)
    {
        if(4 == *it)
        {
            number.erase(it);
        }
    }

    for(auto it = number.begin(); it != number.end(); ++it)
    {
        cout << *it << "   ";
    }
    cout << endl;
}

void test2()
{
    vector<int> number = {1, 3, 4, 4, 4, 5, 4, 4, 7};
    for(auto it = number.begin(); it != number.end(); ++it)
    {
        cout << *it << "   ";
    }

    cout << endl << "执行删除操作" << endl;
    for(auto it = number.begin(); it != number.end(); )
    {
        if(4 == *it)
        {
            number.erase(it);
        }
        else
        {
            ++it;
        }
    }

    for(auto it = number.begin(); it != number.end(); ++it)
    {
        cout << *it << "   ";
    }
    cout << endl;
}
int main(int argc, char *argv[])
{
    test2();
    return 0;
}

